Constant Type | Value |
---|---|
CONSTANT_Class | 7 |
CONSTANT_Fieldref | 9 |
CONSTANT_Methodref | 10 |
CONSTANT_InterfaceMethodref | 11 |
CONSTANT_String | 8 |
CONSTANT_Integer | 3 |
CONSTANT_Float | 4 |
CONSTANT_Long | 5 |
CONSTANT_Double | 6 |
CONSTANT_NameAndType | 12 |
CONSTANT_Utf8 | 1 |
CONSTANT_Unicode | 2 |
Each tag byte is then followed by one or more bytes giving more information about the specific constant.
CONSTANT_Class
is used to represent a class or an interface.
CONSTANT_Class_info {
u1 tag;
u2 name_index;
}
CONSTANT_Class
CONSTANT_Utf8
giving the string name of the class.
Because arrays are objects, the opcodes anewarray
and multianewarray
can reference array "classes" via CONSTANT_Class
items in the constant pool. In this case, the name of the class is its signature. For example, the class name for
int[][]
is
The class name for[[I
Thread[]
is
"[Ljava.lang.Thread;"
CONSTANT_Fieldref_info {
u1 tag;
u2 class_index;
u2 name_and_type_index;
}
CONSTANT_Methodref_info {
u1 tag;
u2 class_index;
u2 name_and_type_index;
}
CONSTANT_InterfaceMethodref_info {
u1 tag;
u2 class_index;
u2 name_and_type_index;
}
CONSTANT_Fieldref
, CONSTANT_Methodref
, or CONSTANT_InterfaceMethodref.
constant_pool[class_index]
will be an entry of type CONSTANT_Class
giving the name of the class or interface containing the field or method.
For CONSTANT_Fieldref
and CONSTANT_Methodref
, the CONSTANT_Class
item must be an actual class. For CONSTANT_InterfaceMethodref
, the item must be an interface which purports to implement the given method.
constant_pool[name_and_type_index]
will be an entry of type CONSTANT_NameAndType.
This constant pool entry indicates the name and signature of the field or method.
CONSTANT_String_info {
u1 tag;
u2 string_index;
}
CONSTANT_String
constant_pool[string_index]
is a CONSTANT_Utf8
string giving the value to which the String object is initialized.
CONSTANT_Integer
and CONSTANT_Float
represent four-byte constants.
CONSTANT_Integer_info {
u1 tag;
u4 bytes;
}
CONSTANT_Float_info {
u1 tag;
u4 bytes;
}
CONSTANT_Integer
or CONSTANT_Float
CONSTANT_Long
and CONSTANT_Double
represent eight-byte constants.
All eight-byte constants take up two spots in the constant pool. If this is the nth item in the constant pool, then the next item will be numbered n+2.CONSTANT_Long_info {
u1 tag;
u4 high_bytes;
u4 low_bytes;
}
CONSTANT_Double_info {
u1 tag;
u4 high_bytes;
u4 low_bytes;
}
CONSTANT_Long
or CONSTANT_Double
.
CONSTANT_Long
, the 64-bit value is (high_bytes
<< 32) + low_bytes
.
For CONSTANT_Double
, the 64-bit value, high_bytes
and low_bytes
together represent the standard IEEE 754 representation of the double-precision floating point number.
CONSTANT_NameAndType
is used to represent a field or method, without indicating which class it belongs to.
CONSTANT_NameAndType_info {
u1 tag;
u2 name_index;
u2 signature_index;
}
CONSTANT_NameAndType.
constant_pool[name_index]
is a CONSTANT_Utf8
string giving the name of the field or method.
constant_pool[signature_index]
is a CONSTANT_Utf8
string giving the signature of the field or method.
CONSTANT_Utf8
and CONSTANT_Unicode
are used to represent constant string values.
CONSTANT_Utf8
strings are "encoded" so that strings containing only non-null ASCII characters, can be represented using only one byte per character, but characters of up to 16 bits can be represented:
All characters in the range 0x0001 to 0x007F are represented by a single byte:
+-+-+-+-+-+-+-+-+
|0|7bits of data|
+-+-+-+-+-+-+-+-+
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
|1|1|0| 5 bits | |1|0| 6 bits |
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
|1|1|1|0|4 bits | |1|0| 6 bits | |1|0| 6 bits |
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
There are two differences between this format and the "standard" UTF-8 format. First, the null byte (0x00) is encoded in two-byte format rather than one-byte, so that our strings never have embedded nulls. Second, only the one-byte, two-byte, and three-byte formats are used. We do not recognize the longer formats.
CONSTANT_Utf8_info {
u1 tag;
u2 length;
u1 bytes[length];
}
CONSTANT_Unicode_info {
u1 tag;
u2 length;
u2 bytes[length];
}
CONSTANT_Utf8
or CONSTANT_Unicode
.